package com.jftone.bh.app.action;

import com.jftone.bh.app.config.SysConst;
import com.jftone.bh.app.model.NtbVipCard;
import com.jftone.bh.app.service.BaseOrderService;
import com.jftone.bh.app.service.VipOrderService;
import org.apache.log4j.Logger;
import org.jftone.annotation.Autowired;
import org.jftone.annotation.Controller;
import org.jftone.exception.ActionException;
import org.jftone.util.IData;
import org.jftone.util.StringUtil;

import java.util.List;


@Controller(mapping="/baseOrderAction")
public class BaseOrderAction extends BaseAction {

	private Logger logger = Logger.getLogger(BaseOrderAction.class);
	
	@Autowired
	private BaseOrderService service;

	public void query() throws ActionException {
		IData<String, Object> data = getData();
		String account = data.getString("account", "");
		String orderNo = data.getString("orderNo", "");
		String status = data.getString("status", "");
		String userId = data.getString("userId", "");
		String sTime = data.getString("sTime", "");
		String eTime = data.getString("eTime", "");
		this.putRenderInfo("sTime", sTime);
		this.putRenderInfo("eTime", eTime);
		this.putRenderInfo("userId", userId);
		this.putRenderInfo("status", status);
		this.putRenderInfo("orderNo", orderNo);
		this.putRenderInfo("account", account);
		this.putRenderInfo("userId", userId);
		try {
			//设置功能按钮
			setMenuFuncDerictive();
			//设置分页组件
			setPageDerictive();
			putParam("sTime", sTime);
			putParam("eTime", eTime);
			putParam("userId", userId);
			putParam("status", status);
			putParam("orderNo", orderNo);
			putParam("account", account);
			putParam("userId", userId);
			putParam(SysConst.QUERY_PARAMS, getParam());

			List<IData<String, Object>> list = service.queryList(data, getPage());
			this.putRenderInfo("list", list);
			this.render("base_order/order_list.html");
		} catch (Exception e) {
			logger.error("查询预约订单列表错误" + e.getMessage(), e);
			throw new ActionException("查询预约订单列表错误" + e.getMessage(), e);
		}
	}
	public void useOrder() throws ActionException{
		IData<String, Object> data = getData();
		String dataId = data.getString("dataId", "");
		if(StringUtil.isBlank(dataId) || !StringUtil.isNumber(dataId)){
			this.alertMsg("参数传值错误");
			return;
		}
		try {
			int resultCode = service.useOrder(Long.parseLong(dataId));
			if(resultCode == 0){
				this.showMsg("操作成功", "?method=query");
			}else if(resultCode == 1){
				this.errorMsg("参数错误", "参数错误","参数错误","?method=query");
			}else if(resultCode == 2){
				this.errorMsg("订单状态错误", "订单状态不属于创建状态","订单状态创建状态","?method=query");
			}else if(resultCode == 3){
				this.errorMsg("使用时间错误", "预约时间不为今天或今天之前","请注意预约时间","?method=query");
			}
		} catch (Exception e) {
			logger.error("操作数据错误"+e.getMessage(), e);
			throw new ActionException("操作数据错误"+e.getMessage(), e);
		}

	}

}
